﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FruitItem : MonoBehaviour
{
    public GameObject collectedEffect;
    public int Score = 100;

    private SpriteRenderer   _spriteRenderer;
    private CircleCollider2D   _circleCollider2D;
    // Start is called before the first frame update
    void Start()
    {
        _spriteRenderer = GetComponent<SpriteRenderer>();
        _circleCollider2D = GetComponent<CircleCollider2D>();
    }


    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.gameObject.tag=="Player")
        {
            _spriteRenderer.enabled = false;
            _circleCollider2D.enabled = false;

            collectedEffect.SetActive(true);

            GameController.Instance.totalScore += Score;
            GameController.Instance.UpdateTotalScore();

            Destroy(gameObject, 0.2f);
        }
    }
}
